import { createStore } from 'vuex';

export default createStore({
  state: {
    token: '',
    user: {
      id: null,
      name: '',
      avatar: ''
    }
  },
  mutations: {
    setToken(state, token) {
      state.token = token;
    },
    setUser(state, user) {
      state.user = user;
    }
  },
  actions: {
    updateToken({ commit }, token) {
      commit('setToken', token);
    },
    updateUser({ commit }, user) {
      commit('setUser', user);
    }
  },
  getters: {
    getToken: (state) => state.token,
    getUser: (state) => state.user
  }
});
